package com.flowable.project.test;



import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.type.LogicalType;
import com.flowable.project.model.request.SendHttpModel;
import com.flowable.project.rocketmq.PayProducer;
import com.flowable.project.service.OpenApiService;
import com.flowable.project.service.impl.OpenApiServiceImpl;
import com.flowable.project.util.JsonData;
import com.flowable.project.util.JsonUtil;
import com.flowable.project.util.SpringUtil;
import io.swagger.util.Json;
import org.flowable.common.engine.api.delegate.Expression;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

import static com.fasterxml.jackson.databind.type.LogicalType.Map;


public class ToUpperCaseFieldInjected implements JavaDelegate {
    private Expression urlId;
    private Expression httpType;
    private Expression data;
    @Override
    public void execute(DelegateExecution execution) {
        PayProducer producer = new PayProducer();
        String url_id = (String) urlId.getValue(execution);
        String http_type = (String) httpType.getValue(execution);
        String datas = (String) data.getValue(execution);
        Map<String,String> map = JSON.parseObject(datas,Map.class);
        SendHttpModel sendHttpModel = new SendHttpModel();
        sendHttpModel.setUrlId(Integer.valueOf(url_id));
        sendHttpModel.setHttpType(http_type);
        sendHttpModel.setData(map);
        OpenApiService openApiService = SpringUtil.getBean(OpenApiService.class);
        JsonData jsonData = openApiService.sendHttp(sendHttpModel);
        String executionId = execution.getId();
//        RuntimeService runtimeService = SpringUtil.getBean(RuntimeService.class);
//        runtimeService.messageEventReceived("isok",executionId);
        System.out.println("================"+executionId+"=================");
        producer.sendMessage(jsonData.toString(),"",executionId);
        System.out.println(executionId+"的消息发送的消息对列成功！！！yyyyyyyy");
    }
}
